﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TXTD.Admin.Data.Entitys.System;
using TXTD.Admin.Interface.System;
using TXTD.Admin.Model.Core;
using TXTD.Admin.Model.Modules.System;

namespace TXTD.Admin.WebApi.Modules.System
{
    //[Authorize]
    [ApiController]
    [Route("api/System/[controller]")]
    public class SysRoleController : ControllerBase
    {
        private ISysRoleService service;
        public SysRoleController(ISysRoleService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllList")]
        public ResultModel GetAllList()
        {
            return ResultModel.ResultBy(service.GetAllList());
        }
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetPageList")]
        public ResultModel GetPageList([FromQuery] SysRole model)
        {
            return ResultModel.ResultBy(service.GetPageList(model)) ;
        }
        [HttpPost("Add")]
        public ResultModel Add(SysRole model)
        {
            return ResultModel.ResultByCount(service.Add(model));
        }
        [HttpPost("Update")]
        public ResultModel Update(SysRole model)
        {
            return ResultModel.ResultByCount(service.Update(model));
        }
        [HttpPost("Delete")]
        public ResultModel Delete(string id)
        {
            return ResultModel.ResultByCount(service.DeleteById(id));
        }
        [HttpPost("UpdateEnabled")]
        public ResultModel UpdateEnabled(SysRole model)
        {
            return ResultModel.ResultByCount(service.UpdateEnabled(model));
        }
        [HttpGet("GetRoleMenuByRoleId")]
        public ResultModel GetRoleMenuByRoleId(string roleId)
        {
            return ResultModel.ResultBy(service.GetRoleMenuByRoleId(roleId));
        }
        /// <summary>
        /// 保存角色菜单
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="menuIds"></param>
        /// <returns></returns>
        [HttpPost("SaveRoleMenu")]
        public ResultModel SaveRoleMenu(RoleMenuModel roleMenuModel)
        {
            return ResultModel.ResultByCount(service.SaveRoleMenu(roleMenuModel));
        }
    }
}
